//
//  FYVisitorTableViewController.swift
//  Mircore
//
//  Created by apple on 16/8/8.
//  Copyright © 2016年 飞羽. All rights reserved.
//

import UIKit

//访客视图控制器
class FYVisitorTableViewController: UITableViewController {

    //是否登录的标记
    
    var isLogin :Bool  = FYUserAccountViewModel.sharedUserAccount.isLogin
    
     var visitorView : FYVisitorView?
    
    override  func loadView() {
        //登录状态下使用系统提供的视图
        
        if  isLogin  {
        
         super.loadView()
        
        }else  {
        
        //未登录视图  使用自己的定义访客视图
            
            visitorView  = FYVisitorView()
            
            visitorView?.loginClosure  = {[weak  self]  in
                
            
              self?.reqeustOAuthVC()
            
            }
            
            view   = visitorView
            
            //设置导航栏按钮
            
            setNavUI()
        
        }
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
     }

    
    private  func  setNavUI()  {
    
      navigationItem.leftBarButtonItem  = UIBarButtonItem(title: "注册", target: self, action: #selector(FYVisitorTableViewController.registerAction))
    
        
        navigationItem.rightBarButtonItem  = UIBarButtonItem(title: "登录", target: self, action: #selector(FYVisitorTableViewController.loginAction))
    }
    
    //MARK:-点击事件
    
    @objc  private func  registerAction() {
    
      reqeustOAuthVC()
    }
   
    
    @objc  private  func  loginAction() {
    
     reqeustOAuthVC()
    }
    
    //登录第三方的函数
    
    private func  reqeustOAuthVC()  {
    
        let oAuthVC = CZOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        
        presentViewController(nav, animated: true, completion: nil)
        
        
      
    }
}
